package com.steven.download;

/**
 * @description:
 * @create: 2021-03-14
 * @author: yanzhiwen
 */
public enum DownloadStatus {
    IDLE(0), DOWNLOADING(1), PAUSE(2), FAIL(3),SUCCESS(4);
    private int value = 0;

    private DownloadStatus(int value) {     //必须是private的，否则编译错误
        this.value = value;
    }

    public static DownloadStatus valueOf(int value) {    //手写的从int到enum的转换函数
        switch (value) {
            case 0:
                return IDLE;
            case 1:
                return DOWNLOADING;
            case 2:
                return PAUSE;
            case 3:
                return FAIL;
            case 4:
                return SUCCESS;
            default:
                return null;
        }
    }

    public int value() {
        return this.value;
    }
}
